package com.zhuiYun.project.api.WxLogin.mapper;

import com.zhuiYun.project.api.login.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @Description TODO 小程序微信授权登录
 * @ClassName UserLoginMapper
 * @Author HH
 * @Date 2023/4/3 18:25
 **/
@Mapper
public interface WxLoginMapper{

    /**
    * @Description 根据openid查询用户信息
    * @Author HH
    * @Date 2023/4/10 18:48
    * @Return com.zhuiYun.project.api.login.entity.User
    * @param openid
    */
    @Select("<script>SELECT id,nick_name,password,gender,mail,phone,avatar_url,openid,create_time,update_time FROM user WHERE openid = #{openid}</script>")
    User getUserInfoByOpenid(String openid);

    /**
    * @Description 新增用户
    * @Author HH
    * @Date 2023/4/10 18:49
    * @Return int
    * @param user
    */
    @Insert("<script>INSERT INTO user (nick_name,gender,phone,avatar_url,openid,create_time,update_time) VALUES (#{nickName},#{gender},#{phone},#{avatarUrl},#{openid},now(),now())</script>")
    int insertUser(User user);

    /**
    * @Description 根据电话号查询用户信息
    * @Author HH
    * @Date 2023/4/12 14:11
    * @Return com.zhuiYun.project.api.login.entity.User
    * @param phone
    */
    @Select("<script>SELECT id,nick_name,password,gender,mail,phone,avatar_url,openid,create_time,update_time FROM user WHERE phone = #{phone}</script>")
    User getUserInfoByPhone(String phone);

    /**
    * @Description 根据电话号查询用户信息
    * @Author HH
    * @Date 2023/4/12 14:11
    * @Return com.zhuiYun.project.api.login.entity.User
    * @param user
    */
    @Update("<script>UPDATE user SET openid = #{openid} WHERE phone = #{phone}</script>")
    int updateUserByPhone(User user);


}
